import sqlite3
from sys import argv

from quote import parse_hlas1

with open(argv[1]) as input_file:
    quotes = parse_hlas1(input_file.read())
connection = sqlite3.connect(argv[1].replace(".hlas1", ".sqlite"))
cursor = connection.cursor()
cursor.execute("CREATE TABLE quotes (id, author, text, context, datetime, writer)")
cursor.executemany(
    "INSERT INTO quotes VALUES (:id, :author, :text, :context, :datetime, :writer)",
    [quote.to_dict() for quote in quotes],
)
connection.commit()
connection.close()
